1 00:00:00,450 --> 00:00:10,740 Hello and welcome to this video on javascript functions javascript functions are a block of code designed 2 00:00:10,740 --> 00:00:22,260 to perform a certain task so the Turbo's group function is executed or called when some team invokes 3 00:00:22,260 --> 00:00:29,660 it so to invoke it function means you're calling it to perform a task. 4 00:00:29,670 --> 00:00:34,680 There are many built in functions in javascript. 5 00:00:34,680 --> 00:00:42,300 You may have come across one before core alert that's responsible for a pop up boxes that comes up on 6 00:00:42,300 --> 00:00:43,520 the browser. 7 00:00:43,740 --> 00:00:51,390 You can also create your own functions A Germans group function is defined with the function key word 8 00:00:52,200 --> 00:01:02,820 followed by the name then followed by per Empathy's you must enclose per hour is function names can 9 00:01:03,210 --> 00:01:10,410 contain certain letters digits even underscores and their dollars size. 10 00:01:10,710 --> 00:01:14,800 They also follow the same rules as the variables. 11 00:01:14,800 --> 00:01:23,800 The parentheses may include parameter may include parameter names which are separated by commas so in 12 00:01:23,960 --> 00:01:30,660 it parent this is you can add parameter 1 or parameters to be also known as arguments. 13 00:01:30,810 --> 00:01:40,980 So the code that will be executed by the function is placed inside the curly braces or quarterly brackets 14 00:01:41,290 --> 00:01:51,670 so they the caudell be executed by the function is placed inside the curly brackets function parameters. 15 00:01:51,720 --> 00:02:00,210 Are their names listed in the function definition so where you define a function the actual parameters 16 00:02:00,310 --> 00:02:01,570 are the names. 17 00:02:01,680 --> 00:02:10,650 But when you actually give the function value being known as argument so function arguments are they 18 00:02:10,650 --> 00:02:19,710 real values that I receive by the function when the function is invoked or caught inside a function 19 00:02:20,040 --> 00:02:24,630 the arguments behaves as a local variable. 20 00:02:24,720 --> 00:02:29,900 That means the variable is only available within the scope of function. 21 00:02:31,320 --> 00:02:39,360 Function invocation or when you call it function means something happens that will make the function 22 00:02:39,380 --> 00:02:41,740 to to perform a task. 23 00:02:41,940 --> 00:02:49,140 For example when you click on a button on the website you are invoking a function. 24 00:02:49,140 --> 00:02:56,950 Something happens in response to that click is called Click event but is driven by a function. 25 00:02:57,240 --> 00:03:06,330 Functions also have a return statement so when the javascript function reaches a written statement the 26 00:03:06,330 --> 00:03:14,490 function will stop executing the code stops so the function was invoked or called from his statement. 27 00:03:14,520 --> 00:03:21,990 Ben Jealous group will return to execute the code after invoking this statement. 28 00:03:21,990 --> 00:03:32,980 Functions that often compute Ireton value always return value back to the caller to were invoked the 29 00:03:32,990 --> 00:03:33,980 function. 30 00:03:34,040 --> 00:03:48,240 All right this is a sample function I have created that will add two numbers together and return value. 31 00:03:48,330 --> 00:03:57,210 Functions are very useful in that you can define a function once and then reuse it as many times as 32 00:03:57,210 --> 00:03:58,000 possible. 33 00:03:58,020 --> 00:04:04,230 If you think about the alerts function that was the final ones and then you can use it any time you 34 00:04:04,230 --> 00:04:07,180 want from within the browser. 35 00:04:07,260 --> 00:04:18,270 All right so this is a function I have written to add two numbers together not to multiply two numbers 36 00:04:18,270 --> 00:04:19,540 together. 37 00:04:19,860 --> 00:04:27,510 So this is a keyword function and then giving it a name chord add numbers. 38 00:04:27,540 --> 00:04:37,390 So it's all in between the parentheses are parameters so the only thing without asserting value inside 39 00:04:37,390 --> 00:04:45,270 the premises is called parameters to a perimeter parameter number one and then parameter number two. 40 00:04:45,590 --> 00:04:55,310 So I've also got a variable here called resort and the value only variable is number one times number 41 00:04:55,320 --> 00:04:56,450 two. 42 00:04:56,640 --> 00:05:01,820 So I change that to a plus. 43 00:05:01,830 --> 00:05:10,780 Okay so so the value of this variable result will be a number one plus number to return here. 44 00:05:10,800 --> 00:05:14,950 The written statement is used to return the result. 45 00:05:15,240 --> 00:05:21,590 So when you actually pass actual values they're called argument. 46 00:05:21,840 --> 00:05:26,040 So to call the function created a function here. 47 00:05:26,160 --> 00:05:28,540 So to call the function. 48 00:05:28,590 --> 00:05:35,730 So remember my side function now because this is a quote liberators So I'm calling the function outside 49 00:05:36,120 --> 00:05:37,290 of the function. 50 00:05:37,290 --> 00:05:42,060 Self CORELY is an alert and I've called it by its name. 51 00:05:42,110 --> 00:05:47,850 His name is called numbers and I'm giving it to arguments. 52 00:05:47,880 --> 00:05:52,040 So when you actually pass rule values poured arguments. 53 00:05:52,140 --> 00:05:57,540 So because he specified here that it takes two parameters 1 and 2. 54 00:05:57,780 --> 00:06:04,080 So now you are giving me real values which I known R's arguments have given me two arguments and there 55 00:06:04,080 --> 00:06:04,800 they are. 56 00:06:04,800 --> 00:06:15,480 So when I executed this alert function this alert function here it will show the results of the number 57 00:06:15,500 --> 00:06:18,180 of the two values added together. 58 00:06:18,300 --> 00:06:25,530 Right so this is an alert which is a function on his own built into javascript and then of course my 59 00:06:25,530 --> 00:06:33,210 own function I've created called Ad numbers so functions are always identified by the parentheses. 60 00:06:33,210 --> 00:06:38,860 This is my parentheses for my function and I've passed it to arguments. 61 00:06:38,870 --> 00:06:39,300 So. 62 00:06:39,310 --> 00:06:46,830 The Argue the values are real record arguments for where you expect something to be passed in the call 63 00:06:46,860 --> 00:06:51,780 parameters as parameters 1 and parameter to the state. 64 00:06:51,810 --> 00:06:55,560 I don't know why the vote would be so then known as paratrooper's. 65 00:06:55,680 --> 00:06:59,740 But when you parse out all values they become arguments. 66 00:06:59,820 --> 00:07:02,690 So this function here takes two arguments. 67 00:07:02,820 --> 00:07:07,670 So let me run that and then you see the result. 68 00:07:07,800 --> 00:07:16,650 They go 16 so it's giving me the result of 16 which is an added number one number two together and the 69 00:07:16,650 --> 00:07:18,270 result is 16. 70 00:07:18,270 --> 00:07:26,140 So this is why the alert from action as printed on the screen or displayed on the screen. 71 00:07:26,160 --> 00:07:30,040 So in this video I gave you a brief introduction to. 72 00:07:30,130 --> 00:07:36,710 Functions and how they are created and the benefits of having functions. 73 00:07:36,760 --> 00:07:40,860 I hope the video has been useful. 74 00:07:40,870 --> 00:07:46,420 If there are parts of the videos or if you don't understand any parts of it please message me. 75 00:07:46,420 --> 00:07:48,830 I'll be more than happy to help. 76 00:07:49,000 --> 00:07:50,860 Thank you so much for your time.